public class test {
    public static Object addLast;

    public class ListNode {
        int val;
        ListNode next = null;

        ListNode(int val) {
            this.val = val;
        }
    }
    ListNode head = null;

    public class PalindromeList {
        public boolean chkPalindrome(ListNode A) {
            if(A==null){
                return true;
            }
            ListNode fast=A;
            ListNode slow=A;
            while(fast!=null&&fast.next!=null){
                fast=fast.next.next;
                slow=slow.next;
            }
            ListNode cur=slow.next;
            while(cur!=null){
                ListNode curNext=cur.next;
                cur.next=slow;
                slow=cur;
                cur=curNext;
            }
            while(A!=null){
                if(A.val!=slow.val){
                    return false;
                }
                if(A.next==slow){
                    return true;
                }
                A=A.next;
                slow=slow.next;
            }
            return true;
        }

    }
    public static void addLast(int data) {
        ListNode node=new ListNode(data);
        ListNode cur=head;
        if(this.head==null){
            this.head=node;
        }
        while(cur.next!=null){
            cur=cur.next;
        }
        cur.next=node;
    }
}
